# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=pcileech
pkgver=4.19.4
_pkgver=4.19
__pkgver=20251005
pkgrel=1
pkgdesc='Tool, which uses PCIe hardware devices to read and write from the target system memory.'
arch=('x86_64' 'aarch64')
groups=('blackarch' 'blackarch-hardware' 'blackarch-reversing')
url='https://github.com/ufrisk/pcileech/releases'
license=('AGPL-3.0-only')
depends=('libusb' 'leechcore')
optdepends=('linux-headers' 'linux-lts-headers' 'linux-hardened-headers'
            'linux-rt-headers' 'linux-rt-lts-headers' 'linux-zen-headers')
options=('!strip')
source_x86_64=("https://github.com/ufrisk/pcileech/releases/download/v$_pkgver/PCILeech_files_and_binaries_v$pkgver-linux_x64-$__pkgver.tar.gz")
source_aarch64=("https://github.com/ufrisk/pcileech/releases/download/v$_pkgver/PCILeech_files_and_binaries_v$pkgver-linux_aarch64-$__pkgver.tar.gz")
sha512sums_x86_64=('340f0791a3b1e11c11aa046f5ffac855c69ea86d872397c4246ee9daf61d932e68fcc09247756242175e9d3d2161a0cb3ce83d54f63338c7e3f2cc0e1c66dd0a')
sha512sums_aarch64=('d302e9caeb8867d76a3b223f474627d1ccc5eac6ac216a296a4c4b7e7918530610d5f548f90e49f3380871cb27faad7c20e89213d1bee9b8d4d1f3938543fb68')

package() {
  install -dm 755 "$pkgdir/usr/bin"
  install -dm 755 "$pkgdir/usr/share/$pkgname"

  cp -a --no-preserve=ownership * "$pkgdir/usr/share/$pkgname/"

  chmod 755 "$pkgdir/usr/share/$pkgname/$pkgname"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec ./$pkgname "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"

  rm -f \
    "$pkgdir/usr/share/$pkgname/PCILeech_files_and_binaries_v$pkgver-linux_x64-$__pkgver.tar.gz" \
    "$pkgdir/usr/share/$pkgname/PCILeech_files_and_binaries_v$pkgver-linux_aarch64-$__pkgver.tar.gz"
}

